﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using VelesDBCore;

namespace VelesDBBL
{
    public class DBManager
    {
        private static string server;
        public static string Server
        { set { DBManager.server = value; } }

        private static string dbName;
        public static string DbName
        { set { DBManager.dbName = value; } }

        private static string saPassword;
        public static string SaPassword
        { set { DBManager.saPassword = value; } }


        private static DBCore context = null;

        public static DBCore Context
        {

            get
            {
                if (context == null)
                {
                    System.Data.EntityClient.EntityConnectionStringBuilder conn = new System.Data.EntityClient.EntityConnectionStringBuilder();
                    conn.Provider = "System.Data.SqlClient";
                    conn.ProviderConnectionString = String.Format(@"Data Source={0};Initial Catalog={1};User ID=sa;Password={2}",
                        server, dbName, saPassword);
                    conn.Metadata = "res://*/VelesDB.csdl|res://*/VelesDB.ssdl|res://*/VelesDB.msl";
                    context = new DBCore(conn.ToString());
                }

                return context;
            }
        }
    }
}
